package com.atguigu.sparkcore.rdd.tranformsinglevale

import com.atguigu.sparkcore.util.MySparkContextUtil
import org.apache.spark.rdd.{ParallelCollectionRDD, RDD}
import org.apache.spark.{SparkConf, SparkContext}

import scala.collection.Map
import scala.reflect.ClassTag

/**
  * rdd转换-Glom
  * 将每一个分区的元素合并为一个数组
  */
object Glom {

  def main(args: Array[String]): Unit = {

    // 获取sparkContext
    val sc = MySparkContextUtil.get(args)

    // 创建rdd
    val list: Array[Int] = Array(10, 20, 30, 40, 50, 60)
    val rdd: RDD[Int] = sc.makeRDD(list, 2)

    // 转换rdd
    val result: RDD[Array[Int]] = rdd.glom()

    // 输出
    println(rdd.collect().size)
    println(result.collect().size)
    result.collect().foreach(list => list.map(println))

    // 关闭资源
    MySparkContextUtil.close(sc)
  }
}

